package com.io.file;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class file2FileInputStream {
	public static void main(String[] args) {
		File file = new File(
				"D:\\eclipse-jee-juno-SR1-win32\\workplace\\JavaSrc\\src\\com\\io\\input\\file.txt");
		try {
			FileInputStream fin = new FileInputStream(file);
			byte[] filebt;
			try {
				filebt = readStream(fin);
				for (int i = 0; i < filebt.length; i++) {
					System.out.print((char) filebt[i]);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	private static byte[] readStream(FileInputStream fin) throws Exception {
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = -1;
		while ((len = fin.read(buffer)) != -1) {
			outStream.write(buffer, 0, len);
		}
		outStream.close();
		fin.close();
		return outStream.toByteArray();
	}
}
